#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc,char **argv)
{
	int fd;
	int val;
	char dev_name[10]="/dev/led";

	if (argc != 3)
	{
		printf("Usage :\n");
		printf("%s num<1~4> <on|off>.\n", argv[0]);
		return 0;
	}
	
	if(argv[1][0] -'0'>4)
	{
		printf("Usage :\n");
		printf("%s num<1~4> <on|off>.\n", argv[0]);

		return 0;
	}
	
	dev_name[8] = argv[1][0];
	dev_name[9] = '\0';
	fd =open(dev_name,O_RDWR);
	if(fd<0)
	{
		printf("can't open %s",dev_name);
	}
	

	if (strcmp(argv[2], "on") == 0)
	{
		val  = 1;
	}
	else
	{
		val  = 0;
	}
	
	write(fd,&val,4);

	return 0;
}
